#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:6031)

#include <iostream>
#include <string>
using namespace std;

string addStrings(string num1, string num2)
{
    int sumDigits = num1.size() > num2.size() ? num1.size() : num2.size();
    string sum(sumDigits, 'x');

    int count1 = num1.size() - 1;
    int count2 = num2.size() - 1;
    int i = 0;
    int carryOver = 0;
    while (count1 >= 0 || count2 >= 0)
    {
        if (count1 >= 0 && count2 >= 0)
        {
            sum[i] = num1[count1] - '0' + num2[count2] + carryOver;
            --count1;
            --count2;
        }
        else if (count1 >= 0 && count2 < 0)
        {
            sum[i] = num1[count1] + carryOver;
            --count1;
        }
        else if (count1 < 0 && count2 >= 0)
        {
            sum[i] = num2[count2] + carryOver;
            --count2;
        }
        carryOver = 0;
        if (sum[i] - '0' > 9)
        {
            carryOver = 1;
            sum[i] -= 10;
        }

        ++i;
    }

    if (carryOver == 1)
    {
        sum += '1';

    }

    int left = 0;
    int right = sum.size() - 1;
    while (left < right)
    {
        swap(sum[left], sum[right]);
        ++left;
        --right;
    }

    return sum;
}

int main()
{
    string s1("6");
    string s2("501");
    string s3 = addStrings(s1, s2);
    cout << s3 << endl;
    return 0;
}